package com.wocai.jrt.orgadmin.product.service.impl;

import javax.inject.Inject;
import javax.inject.Named;

import com.wocai.jrt.orgadmin.product.dao.ProductGroupDao;
import com.wocai.jrt.orgadmin.product.model.Product;
import com.wocai.jrt.orgadmin.product.model.ProductGroup;
import com.wocai.jrt.orgadmin.product.model.ProductGroupBean;
import com.wocai.jrt.orgadmin.product.service.spi.ProductGroupService;
import com.wocai.jrt.orgadmin.product.service.spi.ProductService;
import com.vteba.common.exception.ServiceException;
import com.vteba.service.generic.impl.MyBatisServiceImpl;
import com.vteba.tx.jdbc.mybatis.spi.BaseDao;

/**
 * 产品组相关的service业务实现。
 * @author yinlei
 * @date 2016-1-4 10:56:47
 */
@Named
public class ProductGroupServiceImpl extends MyBatisServiceImpl<ProductGroup, ProductGroupBean, String> implements ProductGroupService {
	// 添加了方法后，记得改为private
	protected ProductGroupDao productGroupDao;
	@Inject
	private ProductService productServiceImpl;
	
	@Override
	@Inject
	public void setBaseDao(BaseDao<ProductGroup, ProductGroupBean, String> productGroupDao) {
		this.baseDao = productGroupDao;
		this.productGroupDao = (ProductGroupDao) productGroupDao;
	}

	@Override
	public int deleteProductGroupById(String id) {
		int result;
		try {
			Product newProduct = new Product();
			newProduct.setProductGroupId("");
			Product oldProduct = new Product();
			oldProduct.setProductGroupId(id);
			productServiceImpl.updateBulks(newProduct, oldProduct);
			result = productGroupDao.deleteById(id);
		} catch (Exception e) {
			throw new ServiceException();
		}
		return result;
	}
}
